package com.t282.sale.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.t282.sale.pojo.Product;
import com.t282.sale.pojo.Storage;
import com.t282.sale.service.ProductService;
import com.t282.sale.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mr.Chen
 * @since 2021-05-19
 */
@Controller
@RequestMapping("/storage")
public class StorageController {

    @Autowired
    private StorageService storageService;

    @Autowired
    private ProductService productService;

    @RequestMapping("/getStkPage")
    @ResponseBody
    public Page getPage(@RequestParam(required = false,defaultValue = "1") int pageIndex,
                        @RequestParam(required = false) String stkWarehouse){

        Page<Storage> stpage = new Page<>(pageIndex,5);

        QueryWrapper<Storage> storageQuery = new QueryWrapper<>();
        storageQuery.like("stk_warehouse",stkWarehouse);
        Page<Storage> page1 = storageService.page(stpage,storageQuery);

        return page1;
    }

    @RequestMapping("/getPro")
    @ResponseBody
    public Page getPro(@RequestParam(required = false,defaultValue = "1") int pageIndex,
                       @RequestParam(required = false) String prodName){
        Page<Product> page = new Page<>(pageIndex,5);

        QueryWrapper<Product> productQuery = new QueryWrapper<>();

        productQuery.like("prod_Name",prodName);

        Page<Product> page2 = productService.page(page,productQuery);

        return page2;
    }
}

